//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - SaaS Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================



using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;
using Shp.Runtime.Contract;

namespace LitwareHR.Portfolio.Gateways
{
    static public class PresentationGateway
    {
        static public int GetConfiguredLayout(string tenantAlias)
        {
            using (UnSecureChannel channel = new UnSecureChannel())
            {
                return channel.GetConfiguredLayout(tenantAlias);
            }
        }

        static public string GetConfiguredStyle(string tenantAlias)
        {
            using (UnSecureChannel channel = new UnSecureChannel())
            {
                return channel.GetConfiguredStyle(tenantAlias);
            }
        }

        static public StringPair[] GetMainMenu(string tenantAlias, bool isPublic)
        {
            using (UnSecureChannel channel = new UnSecureChannel())
            {
                return channel.GetMainMenu(tenantAlias, isPublic);
            }
        }

        static public KeyValuePair<int, string>[] GetLayoutList()
        {
            using (SecureChannel channel = new SecureChannel())
            {
                return channel.GetLayoutList();
            }
        }

        static public KeyValuePair<Guid, string>[] GetStyleList()
        {
            using (SecureChannel channel = new SecureChannel())
            {
                return channel.GetStyleList();
            }
        }

        static public void UpdatePresentation(int layout, Guid style)
        {
            using (SecureChannel channel = new SecureChannel())
            {
                channel.UpdatePresentation(layout, style);
            }
        }

        static public void AddStyle(string name, Uri url)
        {
            using (SecureChannel channel = new SecureChannel())
            {
                channel.AddStyle(name, url);
            }
        }

        static public MainMenuItem[] GetMainMenuList()
        {
            using (SecureChannel channel = new SecureChannel())
            {
                return channel.GetMainMenuList();
            }
        }

        static public void UpdateMainMenu(MainMenuItem[] menuItems)
        {
            using (SecureChannel channel = new SecureChannel())
            {
                channel.UpdateMainMenu(menuItems);
            }
        }

        static public Guid GetCurrentStyleId()
        {
            using (SecureChannel channel = new SecureChannel())
            {
                return channel.GetCurrentStyleId();
            }
        }

        private class UnSecureChannel : ClientBase<IPresentationUC>, IPresentationUC
        {
            #region IPresentationUC Members

            public int GetConfiguredLayout(string tenantAlias)
            {
                return base.Channel.GetConfiguredLayout(tenantAlias);
            }

            public string GetConfiguredStyle(string tenantAlias)
            {
                return base.Channel.GetConfiguredStyle(tenantAlias);
            }

            public StringPair[] GetMainMenu(string tenantAlias, bool isPublic)
            {
                return base.Channel.GetMainMenu(tenantAlias, isPublic);
            }

            #endregion
        }

        private class SecureChannel : ClientBase<IPresentationSC>, IPresentationSC
        {
            #region IPresentationSC Members

            public KeyValuePair<int, string>[] GetLayoutList()
            {
                return base.Channel.GetLayoutList();
            }

            public KeyValuePair<Guid, string>[] GetStyleList()
            {
                return base.Channel.GetStyleList();
            }

            public void UpdatePresentation(int layout, Guid style)
            {
                base.Channel.UpdatePresentation(layout, style);
            }

            public void AddStyle(string name, Uri url)
            {
                base.Channel.AddStyle(name, url);
            }

            public MainMenuItem[] GetMainMenuList()
            {
                return base.Channel.GetMainMenuList();
            }

            public void UpdateMainMenu(MainMenuItem[] menuItems)
            {
                base.Channel.UpdateMainMenu(menuItems);
            }

            public Guid GetCurrentStyleId()
            {
                return base.Channel.GetCurrentStyleId();
            }

            #endregion
        }
    }
}
